#include "link_stack.h"

// 入队列
int my_push_queue(stack_t *A, int num){
    if(NULL == A){
        return -1;
    }
    push_stack(A, num);
}

// 出队列
int my_pop_queue(stack_t *A, stack_t *B, int *buff){
    if(NULL == A || NULL == B || NULL == buff){
        return -1;
    }
    int temp = 0;
    if(is_empty(B)){
        if(is_empty(A)){
            return -1; // 说明整个队列为空
        }  
        while(!pop_stack(A, &temp)){
            push_stack(B, temp);
        }
    }
    pop_stack(B, buff);
    return 0;
}

int main(int argc, const char *argv[]){
    stack_t *A = NULL;
    create_stack(&A);
    stack_t *B = NULL;
    create_stack(&B);

    // 入队列
    my_push_queue(A, 10);
    my_push_queue(A, 20);
    my_push_queue(A, 30);
    // 出队列
    int value = 0;
    my_pop_queue(A, B, &value);
    printf("value = %d\n", value); // 10
    my_pop_queue(A, B, &value);
    printf("value = %d\n", value); // 20
    // 入队列
    my_push_queue(A, 40);
    my_push_queue(A, 50);
    // 出队列
    my_pop_queue(A, B, &value);
    printf("value = %d\n", value); // 30
    my_pop_queue(A, B, &value);
    printf("value = %d\n", value); // 40
    my_pop_queue(A, B, &value);
    printf("value = %d\n", value); // 50
    int ret = my_pop_queue(A, B, &value);
    printf("%d\n", ret); // -1

    destroy_stack(&A);
    destroy_stack(&B);

    return 0;
}